#! /usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright (c) 2008 jiakuan.net and widenhome.com, All rights reserved.
# 
# Created on 2008-11-1, by Jiakuan Wang <delight.wjk@gmail.com>.
#

"""This script uses msgfmt.py to generate MO files from PO files, and put 
different MO files into different folders.
"""

import os

class Executant:
    def __init__(self, domain, localedir, languages):
        self.domain = domain
        self.localedir = localedir
        self.languages = languages

    def execute(self):
        print '\n', '-' * 60, '\nScript po2mo.py starts to run...\n', '-' * 60
        
        executed = False
        for language in self.languages:
            folder = "".join([self.localedir, '/', language, '/LC_MESSAGES/']);

            # If there is no such language folder, continue to check next 
            # language.
            if not os.path.exists(folder):
                continue
            
            import msgfmt    
            cmd = "".join(['python ' + os.path.abspath(msgfmt.__file__) + ' -o ', 
                           folder, self.domain, '.mo ', folder, self.domain, '.po'])
            os.system(cmd)
            executed = True
            print 'Execute command:', cmd
        
        if executed:
            print '\n', '-' * 60, '\nScript po2mo.py is executed successfully...\n', '-' * 60
        else:
            print '\n', '-' * 60, '\nNo PO files were found, please execute \'po\' option first...\n', '-' * 60
            
if __name__ == '__main__':
    pass